import { h, render } from 'vue';
import MMessage from './index.vue';
import type { MessageProps } from './types';

export const Message = ({ type, content, duration = 2000 }: MessageProps) => {
  return new Promise(() => {
    const onDestroy = () => {
      render(null, document.body);
    };

    const VNode = h(MMessage, {
      type,
      content,
      duration,
      destroy: onDestroy
    });

    render(VNode, document.body);
  });
};

export { default } from './index.vue';
